﻿using System.Collections.Generic;
using System.Net.NetworkInformation;

namespace Jodell.Transport.Ethercat
{
    public class EcHelper
    {
        public static List<EcAdapter> FindAdapters()
        {
            List<EcAdapter> adapters = new List<EcAdapter>();
            NetworkInterface[] adps = NetworkInterface.GetAllNetworkInterfaces();
            // 遍历每个网络接口并输出相关信息
            foreach (NetworkInterface adapter in adps)
            {
                if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||
                    adapter.NetworkInterfaceType == NetworkInterfaceType.GigabitEthernet ||
                    adapter.NetworkInterfaceType == NetworkInterfaceType.FastEthernetT ||
                    adapter.NetworkInterfaceType == NetworkInterfaceType.FastEthernetFx)
                {
                    adapters.Add(new EcAdapter()
                    {
                        Name = string.Format("\\Device\\NPF_{0}", adapter.Id),
                        Description = adapter.Description,
                    });
                }
            }
            return adapters;
        }
    }
}
